<%@ page language="java" import="java.util.*,com.ruohi.util.common.*" pageEncoding="UTF-8"%><%
	String tableName = "gift_card";
	String tablePrefix = Env.getInstance().getProperty("table_prefix");
	String fileds = "id,add_date,add_ip,uuid,no,amount,mem_no,validity_date,is_issue";
	String channelUUID = CommonString.getFormatPara(request.getParameter("channel_uuid"));
	String whereStr = "";
	String orderByStr = "no";
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title><%=Env.getInstance().getProperty("project_name") %></title>
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
	<link href="/backend/style/style.css" rel="stylesheet" type="text/css" />
	<script src="/plugin/jquery/jquery.min.js" type="text/javascript"></script>
  </head>
  <body>
  	<div class="searchForm">
  		<div class="searchCondition">
  			<div class="searchList">
		  		<div class="searchLeft">卡号</div>
		  		<div class="searchRight">
		  			<input type="text" class="jr_text" name="no" id="no" />
		  		</div>
		  	</div>
            <div class="searchList">
		  		<div class="searchLeft">绑定会员号</div>
		  		<div class="searchRight">
		  			<input type="text" class="jr_text" name="mem_no" id="mem_no" />
		  		</div>
		  	</div>
		  	<div class="searchList">
		  		<div class="searchLeft">是否发放</div>
		  		<div class="searchRight">
		  			<select class="jr_select" id="is_issue" name="is_issue">
		  				<option value="">请选择</option>
		  				<option value="1">是</option>
		  				<option value="0">否</option>
		  			</select>
		  		</div>
		  	</div>
  		</div>
  		<div class="searchBtn">
  			<input type="button" class="btn" onclick="doSearch();" value="查询" /><input type="button" style="margin-left: 5px;" class="btn" onclick="doClearForm();" value="重置" />
  		</div>
  	</div>
  	<div style="clear: left;"></div>
  	
	<div class="l-loading" style="display: block" id="pageloading"></div> 
	<div id="maingrid" style="margin: 0; padding: 0"></div>
	<div style="display: none;"></div>
  </body>
</html>
<script src="/plugin/ui/ligerUI/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="/plugin/date/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<script src="/backend/scripts/common.js" prefix="<%=tablePrefix %>" type="text/javascript"></script>
<script type="text/javascript">
	var grid;
	var windowWidth = 500;
	var windowHeight = 150;
	var channelUUID = '<%=channelUUID %>';
	var tableName = "<%=tableName %>";
	var fields = "<%=fileds %>";
	var whereStr = "<%=whereStr %>";
	var orderBy = "<%=orderByStr %>";
	var columnsArr = [];
	var url = "";
	var conditionStr = "";
	var params = [];
	var myToolbar = {
        items: [{
            text: '打开查询',
            click: function(){
                closeAndOpen();
            },
            icon: 'right'
        }]
    };
	jQuery(function() {
		params.push({'name':'enumNo','value':'106013'});
		grid = new Dev21sunGrid({
			toolbar :myToolbar
		});
		jQuery("#pageloading").hide();
	});
	//列数组
	columnsArr = [ 
		{ display:"卡号", name:"no", align:"center", type:"string", width:150 },
		{ display : '添加日期', name : 'add_date', align : 'center' , type : 'date' , width : 120 } ,
		{ display:"添加IP", name:"add_ip", align:"center", type:"string", width:120 },
		{ display : '金额', name : 'amount', align : 'right' , type : 'double' , width : 80 } ,
		{ display:"有效期", name:"validity_date", align:"center", type:"date", width:120 },
		{ display : '绑定会员', name : 'mem_no', align : 'center' , type : 'string' , width : 200, render:function(row){
			return row.mem_no!=null && row.mem_no!="" ? row.mem_no + "&nbsp;&nbsp;<a href=\"javascript://void(0);\" onclick=\"viewHistory('" + row.no + "');\">查看消费记录</a>" : "<font color='red'>未绑定</font>";
		} },
		{ display : '是否已发放', name : 'is_issue', align : 'center' , type : 'is' , width : 80 },
		{ display:"操作", align:"center", type:"string", width:150, render:function(row){
			return row.is_issue==1 ? "<a href=\"javascript://void(0);\" onclick=\"cancelIssue('" + row.uuid + "');\">取消发放</a>&nbsp;&nbsp;<a href=\"javascript://void(0);\" onclick='addAndEdit("+row.__index+", false);'>绑定会员</a>" : "<a href=\"javascript://void(0);\" onclick=\"issue('" + row.uuid + "');\">发放</a>";
		} }
	];
	
	/*列表页条件查询*/
	function doSearch(){
		params = [];
		conditionStr = "";
		var no = jQuery("#no").val();
		if(''!=jQuery.trim(no)){
			conditionStr += " and no like '%"+no+"%' ";
		}
		var mem_no = $.trim($("#mem_no").val());
		if(mem_no != ""){
			conditionStr += " and mem_no like '" + mem_no + "'";
		}
		var is_issue = $.trim($("#is_issue").val());
		if(is_issue != ""){
			conditionStr += " and is_issue=" + is_issue;
		}
		params.push({'name':'enumNo','value':'106013'});
		params.push({'name':'tableName','value':tableName});
		params.push({'name':'fileds','value':fields});
		params.push({'name':'whereStr','value':whereStr+conditionStr});
		params.push({'name':'orderBy','value':orderBy});
		grid.options.parms=params;
		grid.loadData();
	}
	
	function issue(uuid){
		jrConfirm("确定要发放商品卡吗？", function(v){
			$.ajax({
				type:"post",
				url:"/backend/action/ajax_r.jsp",
				data:{flag:"issueCard",enumNo:"106013",uuid:uuid},
				success:function(result){
					if($.trim(result)=="1"){
						grid.loadData();
					}
				}
			});
		});
	}
	
	function cancelIssue(uuid){
		jrConfirm("确定要取消已发放的商品卡吗？", function(v){
			$.ajax({
				type:"post",
				url:"/backend/action/ajax_r.jsp",
				data:{flag:"cancelIssueCard",enumNo:"106013",uuid:uuid},
				success:function(result){
					if($.trim(result)=="1"){
						grid.loadData();
					}
				}
			});
		});
	}
	
	function viewHistory(no){
		jrWindow("/backend/gift.21-sun.com/gift_card/gift_card_pay_history.jsp?no=" + no, "查看消费记录", 700, 500);
	}
</script>